package cn.congzhou.crm.web.controller;

import cn.congzhou.crm.common.qo.QueryObject;
import cn.congzhou.crm.common.vo.CommonResultJson;
import cn.congzhou.crm.common.vo.PageTableData;
import cn.congzhou.crm.domain.School;
import cn.congzhou.crm.service.ISchoolService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/school")
public class SchoolController {

    private Logger log = LoggerFactory.getLogger(SchoolController.class);

    @Autowired
    private ISchoolService schoolService;

    @RequestMapping("/toSchoolDataTable")
    public String toSchoolDataTable(){
        return "/school/schoolDataTable";
    }

    @RequestMapping("/list")
    @ResponseBody
    public CommonResultJson listSchool(QueryObject qo){
        PageTableData<School> schools = schoolService.queryShool(qo);
        log.info("查看校区信息");
        return CommonResultJson.success(schools);
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public CommonResultJson saveOrUpdate(School school){
        schoolService.saveOrUpdate(school);
        return CommonResultJson.success("保存成功");
    }

    @RequestMapping("/delete")
    @ResponseBody
    public CommonResultJson delete(Long id,String name){
        schoolService.deleteById(id);
        return CommonResultJson.success("删除成功");
    }

}
